package com.lf;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.MultipartConfigElement;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.lf.sys.model.SysEmail;
import com.lf.sys.model.SysFolder;
import com.lf.sys.service.EmailService;
import com.lf.sys.service.FolderService;

@Controller
@Configuration
@SpringBootApplication
public class EailBootApplication {
	@Resource
	private EmailService emailService;
	@Resource
	private FolderService folderService;

	private int getUserId() {
		return 1;
	}

	public static void main(String[] args) {
		SpringApplication.run(EailBootApplication.class, args);
	}

	/**
	 * 文件上传配置
	 * 
	 * @return
	 */
	@Bean
	public MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		// 文件最大
		factory.setMaxFileSize("102400KB"); // KB,MB
		/// 设置总上传数据总大小
		factory.setMaxRequestSize("102400KB");
		return factory.createMultipartConfig();
	}

	/**
	 * 跳转
	 */
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public String loginForm(Model model) {
		List<SysEmail> list = emailService.list(this.getUserId());
		model.addAttribute("mailList", list);

		List<SysFolder> folders = folderService.list(getUserId());
		model.addAttribute("folderList", folders);
		return "index";
	}

}
